package com.kgc.scd.controller;

import com.kgc.scd.annotation.RequestShopUser;
import com.kgc.scd.annotation.TokenPermission;
import com.kgc.scd.bean.ShopAddress;
import com.kgc.scd.bean.ShopUser;
import com.kgc.scd.service.WebModifyShopUserService;
import com.kgc.scd.util.RequestResult;
import com.kgc.scd.util.ResultBuildUtil;
import com.kgc.scd.vo.ShopAddressVO;
import com.kgc.scd.vo.ShopUserVO;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * Created On : 2022/11/16.
 * <p>
 * Author : 刘慧枫
 * <p>
 * Description: web端个人资料修改入口
 */
@Slf4j
@RestController
@Api(tags = "02、个人资料修改(lhf)",value = "个人资料修改，密码重置，地址的相关添加修改删除操作")
public class WebModifyShopUserController {

    @Autowired
    private WebModifyShopUserService webModifyShopUserService;

    /**
     * @author : 刘慧枫
     * @date   : 2022/11/17
     * @param  : [gender, birthday, nickname, shopUser]
     * @return : com.kgc.scd.util.RequestResult<com.kgc.scd.bean.ShopUser>
     * @description : 修改个人资料
     */
    @PostMapping("/modUserInfoWeb")
    @ApiOperation(value = "修改个人资料",notes = "基于mybatis-plus，redis，统一返回")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "gender",value = "性别（0男1女）默认是0"),
            @ApiImplicitParam(name = "birthday",value = "生日"),
            @ApiImplicitParam(name = "nickname",value = "昵称",required = false),
            @ApiImplicitParam(name = "headImg",value = "头像图片")
    })
    @ApiResponses({
            @ApiResponse(code = 200,message = "成功"),
            @ApiResponse(code = 998,message = "非空"),
            @ApiResponse(code = 997,message = "敏感词"),
            @ApiResponse(code = 999,message = "失败")
    })
    @TokenPermission
    public RequestResult<ShopUserVO> modUserInfo(@RequestParam(required = false) Integer gender,
                                                 @RequestParam(required = false) Date birthday,
                                                 @RequestParam(required = false) String nickname,
                                                 @RequestParam(required = false) String headImg,
                                                 @ApiIgnore @RequestShopUser ShopUser shopUser){

        if (nickname.equals("")){
            log.warn("------ 昵称不能为空，昵称：{} ------", nickname);
            return ResultBuildUtil.fail("998","修改失败，昵称不能为空");
        }

        log.info("------ 修改个人资料 ------");
        return webModifyShopUserService.modUserInfoUseFeign(gender,birthday,nickname,headImg,shopUser);
    }

    /**
     * @author : 刘慧枫
     * @date   : 2022/11/17
     * @param  : [userOldPwd, userNewPwd, verifyUserNewPwd, shopUser]
     * @return : com.kgc.scd.util.RequestResult<java.util.Map<java.lang.String,java.lang.Object>>
     * @description : 修改密码
     */
    @PostMapping("/modUserPwdWeb")
    @ApiOperation(value = "修改密码",notes = "基于mybatis-plus，redis，统一返回")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userOldPwd",value = "旧密码"),
            @ApiImplicitParam(name = "userNewPwd",value = "新密码"),
            @ApiImplicitParam(name = "verifyUserNewPwd",value = "确认密码")
    })
    @ApiResponses({
            @ApiResponse(code = 200,message = "成功"),
            @ApiResponse(code = 999,message = "失败")
    })
    @TokenPermission
    public RequestResult<Map<String,Object>> modUserPwd(@RequestParam String userOldPwd,
                                                        @RequestParam String userNewPwd,
                                                        @RequestParam String verifyUserNewPwd,
                                                        @ApiIgnore @RequestShopUser ShopUser shopUser){
        log.info("------ 修改密码 ------");
        return webModifyShopUserService.modUserPwdUseFeign(userOldPwd,userNewPwd,verifyUserNewPwd,shopUser);
    }

    /**
     * @author : 刘慧枫
     * @date   : 2022/11/17
     * @param  : [gender, birthday, nickname, shopUser]
     * @return : com.kgc.scd.util.RequestResult<com.kgc.scd.bean.ShopUser>
     * @description : 添加个人地址
     */
    @PostMapping("/addUserAddressWeb")
    @ApiOperation(value = "添加个人地址",notes = "基于mybatis-plus，redis，统一返回")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name",value = "姓名"),
            @ApiImplicitParam(name = "address",value = "地址"),
            @ApiImplicitParam(name = "mobile",value = "手机号"),
            @ApiImplicitParam(name = "status",value = "是否默认地址（1默认）")
    })
    @ApiResponses({
            @ApiResponse(code = 200,message = "成功"),
            @ApiResponse(code = 998,message = "非空"),
            @ApiResponse(code = 997,message = "敏感词"),
            @ApiResponse(code = 996,message = "号码格式错误"),
            @ApiResponse(code = 999,message = "失败")
    })
    @TokenPermission
    public RequestResult<ShopAddressVO> addUserAddress(@RequestParam String name,
                                                            @RequestParam String address,
                                                            @RequestParam String mobile,
                                                            @RequestParam(required = false,defaultValue = "1") Integer status,
                                                            @ApiIgnore @RequestShopUser ShopUser shopUser){
        log.info("------ 添加个人地址 ------");
        return webModifyShopUserService.addUserAddressUseFeign(name,address,mobile,status,shopUser);
    }

    /**
     * @author : 刘慧枫
     * @date   : 2022/11/23
     * @param  : [shopAddress]
     * @return : com.kgc.scd.util.RequestResult<com.kgc.scd.vo.ShopAddressVO>
     * @description : 修改个人地址
     */
    @PostMapping("/modUserAddress")
    @ApiOperation(value = "修改个人地址",notes = "基于mybatis-plus，支持统一返回")
    @ApiResponses({
            @ApiResponse(code = 200,message = "成功"),
            @ApiResponse(code = 999,message = "失败")
    })
    public RequestResult<ShopAddressVO> modUserAddress(@RequestBody ShopAddress shopAddress){
        return webModifyShopUserService.modUserAddress(shopAddress);
    }

    /**
     * @author : 刘慧枫
     * @date   : 2022/11/23
     * @param  : [shopAddress]
     * @return : com.kgc.scd.util.RequestResult<com.kgc.scd.vo.ShopAddressVO>
     * @description : 删除个人地址
     */
    @GetMapping("/delUserAddress")
    @ApiOperation(value = "删除个人地址",notes = "基于mybatis-plus，支持统一返回")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ids",value = "地址id",allowMultiple = true)
    })
    @ApiResponses({
            @ApiResponse(code = 200,message = "成功"),
            @ApiResponse(code = 999,message = "失败")
    })
    public RequestResult<String> delUserAddress(@RequestParam List<String> ids){
        return webModifyShopUserService.delUserAddress(ids);
    }
}
